//index.js
//获取应用实例
var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
Page({
  data: {
    password: '',
    isFocus: false,
    inputPwd: true,
    inputNum: 0,
    passwordFirst: '',
    passwordTwo: '',
    pass_type:'paypwd'
  },
  pwd(e) {
//console.log(11111111111111111111111111)
//console.log(e.detail.value)
//console.log(666)
    let reg = /[^\d]/g
    let mobile = e.detail.value.replace(reg, '')
    this.setData({
      password: mobile
    })
    return mobile
  },
  getFocus() {
    this.setData({
      isFocus: true
    })
  },
  submit() {
    let that = this
    if (that.data.password.length == 6) {
      if (that.data.inputNum == 0) {
        that.data.passwordFirst = that.data.password
        that.data.inputNum = 1
        wx.setNavigationBarTitle({
          title: '再次输入密码',
        })
        that.setData({
          password: '',
          isFocus: false,
          inputPwd: true,
        })
      } else if (that.data.inputNum == 1) {
        that.data.passwordTwo = that.data.password
        if (that.data.passwordFirst == that.data.passwordTwo) {
          wx.showToast({ title: '加载中', icon: 'loading', duration: 10000 });
            let k = wx.getStorageSync('key');
            wx.request({
              //index.php?act=member_account&op=modify_paypwd_step5
              url: ApiUrl + '/index.php?act=member_account&op=modify_'+that.data.pass_type+'_step5',
              data: {
                key: k,
                password: that.data.passwordFirst,
                password1: that.data.passwordTwo
              },
              header: {
                'content-type': 'application/x-www-form-urlencoded'
              },
              method: 'POST',
              success: function (result) {
console.log('设置密码:==>', result);
                if (result.statusCode == 200) {
                  if (result.data.code == 200) {
//console.log(result.data.datas);
                    let res = result.data.datas;
                    if(res == '1'){
                      wx.showToast({
                        title: '设置成功',
                        icon: 'success',
                        success: function (res) {
                          wx.navigateBack({
                            delta: 1
                          })
                        }
                      })
                      wx.hideToast();
                    }

                  }
                }
              }
            })
          // 传that.data.passwordTwo为支付密码
          // wx.showToast({
          //   title: '设置成功',
          //   icon: 'success',
          //   success: function (res) {
          //     wx.navigateBack({
          //       delta: 1
          //     })
          //   }
          // })

        } else {
          wx.showToast({
            title: '两次输入密码不同，请重新输入',
            icon: 'none',
          })
          wx.hideToast();
          wx.setNavigationBarTitle({
            title: '设置支付密码',
          })
          that.setData({
            password: '',
            isFocus: false,
            inputPwd: true,
            inputNum: 0,
            passwordFirst: '',
            passwordTwo: ''
          })
          return false
        }
      }
    }
  },
  /**
     * 生命周期函数--监听页面加载
     */
  onLoad: function (options) {
       if(options.type=='paypwd'){
          this.setData({pass_type:'paypwd'});
      }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})